%% On the Optimal Design of Transfers and Income-Tax Progressivity
% Plots m-theta-lines; no phase out

clear; clc; close all;
%addpath('../../../../Matlab_Figure_Files');

%% Load results

% Load results from grid searches
load('mtheta_bench.mat')
load('mtheta_richerpoor.mat')
load('mtheta_nopareto.mat')

% Adjustment for different ymeans in calibration
ymean_bench = 0.791095377466559;
ymean_richerpoor = 0.807593446799861;
ymean_nopareto = 0.704092915381618;

transfer_grid_richerpoor = (transfer_grid_richerpoor*ymean_richerpoor/ymean_bench)*90185/90373;
transfer_grid_nopareto = (transfer_grid_nopareto*ymean_nopareto/ymean_bench)*90185/90373;

% Optima from TikTak
T_opt_bench = 18689.4170335887/1000;
T_opt_richerpoor = 10505.0876665623/1000;
T_opt_nopareto = 21580.4055704232/1000;

amtr_diff_opt_richerpoor = 0.121437665755090;
amtr_diff_opt_nopareto = -0.08733121539726174;
amtr_diff_opt_bench = 0.03725480874151588;

T_opt_nopareto = T_opt_nopareto*ymean_nopareto/ymean_bench;
T_opt_richerpoor = T_opt_richerpoor*ymean_richerpoor/ymean_bench;

%% Plot Income Inequality

load x_quantile

fig = figure(101);
subplot(1,2,2)
b=bar(x_quantile);
b(1).EdgeColor=[0, 0.4470, 0.7410];
b(2).EdgeColor=[0.8500, 0.3250, 0.0980];
b(3).EdgeColor=[0.9290, 0.6940, 0.1250];
leg = legend('Benchmark','No Pareto','Richer Poor');
set(leg,'Interpreter','LaTex','Location','NorthWest','Fontsize',12)                
legend boxoff
xlabel('Decile','Interpreter','LaTex','Fontsize',12)
ylabel('Average productivity','Interpreter','LaTex','Fontsize',12)
set(gca,'XGrid','off','YGrid','on','Fontsize',12)
set(gca,'TickLabelInterpreter','LaTex')
subplot(1,2,1)
h1 = plot(transfer_grid_bench/1000,amtr_diff_grid_bench,'Color',[0, 0.4470, 0.7410],'linewidth',2); hold on
h2 = plot(T_opt_bench,amtr_diff_opt_bench,'d','MarkerSize',10,'Linewidth',2,'MarkerEdge',[0, 0.4470, 0.7410],'MarkerFace',[0, 0.4470, 0.7410]); hold on
h3 = plot(transfer_grid_nopareto/1000,amtr_diff_grid_nopareto,'Color',[0.8500, 0.3250, 0.0980],'Linewidth',2); hold on
h4 = plot(T_opt_nopareto,amtr_diff_opt_nopareto,'d','MarkerSize',10,'Linewidth',2,'MarkerEdge',[0.8500, 0.3250, 0.0980],'MarkerFace',[0.8500, 0.3250, 0.0980]); hold on
h7 = plot(transfer_grid_richerpoor/1000,amtr_diff_grid_richerpoor,'Color',[0.9290, 0.6940, 0.1250],'Linewidth',2); hold on
h8 = plot(T_opt_richerpoor,amtr_diff_opt_richerpoor,'d','MarkerSize',10,'Linewidth',2,'MarkerEdge',[0.9290, 0.6940, 0.1250],'MarkerFace',[0.9290, 0.6940, 0.1250]); hold on
set(gca,'XGrid','off','YGrid','on','Fontsize',12)  
set(gca,'TickLabelInterpreter','LaTex')
xlabel('Transfer in \$k','Interpreter','LaTex','Fontsize',12)
ylabel('Marginal rates: top-10 minus all','Interpreter','LaTex','Fontsize',12)
leg = legend([h1 h3 h7],{'Benchmark','No Pareto','Richer Poor'});
set(leg,'Interpreter','LaTex','Location','SouthWest','Fontsize',12)
xlim([10 23])
ylim([-0.25 0.18])
legend boxoff
run graph_extended.m
saveas(gcf,'TamtrLine_Inc.pdf')


fig = figure(102);
subplot(1,2,2)
b=bar(x_quantile);
b(1).FaceColor=[0 0 0];
b(2).FaceColor=[0.4 0.4 0.4];
b(3).FaceColor=[0.7 0.7 0.7];
b(1).EdgeColor=[0 0 0];
b(2).EdgeColor=[0.4 0.4 0.4];
b(3).EdgeColor=[0.7 0.7 0.7];
leg = legend('Benchmark','No Pareto','Richer Poor');
set(leg,'Interpreter','LaTex','Location','NorthWest','Fontsize',12)                
legend boxoff
xlabel('Decile','Interpreter','LaTex','Fontsize',12)
ylabel('Average productivity','Interpreter','LaTex','Fontsize',12)
set(gca,'XGrid','off','YGrid','on','Fontsize',12)
set(gca,'TickLabelInterpreter','LaTex')
subplot(1,2,1)
h1 = plot(transfer_grid_bench/1000,amtr_diff_grid_bench,'Color',[0 0 0],'linewidth',2); hold on
h2 = plot(T_opt_bench,amtr_diff_opt_bench,'d','MarkerSize',10,'Linewidth',2,'MarkerEdge',[0 0 0],'MarkerFace',[0 0 0]); hold on
h3 = plot(transfer_grid_nopareto/1000,amtr_diff_grid_nopareto,'Color',[0.4 0.4 0.4],'Linewidth',2); hold on
h4 = plot(T_opt_nopareto,amtr_diff_opt_nopareto,'d','MarkerSize',10,'Linewidth',2,'MarkerEdge',[0.4 0.4 0.4],'MarkerFace',[0.4 0.4 0.4]); hold on
h7 = plot(transfer_grid_richerpoor/1000,amtr_diff_grid_richerpoor,'Color',[0.7 0.7 0.7],'Linewidth',2); hold on
h8 = plot(T_opt_richerpoor,amtr_diff_opt_richerpoor,'d','MarkerSize',10,'Linewidth',2,'MarkerEdge',[0.7 0.7 0.7],'MarkerFace',[0.7 0.7 0.7]); hold on
set(gca,'XGrid','off','YGrid','on','Fontsize',12)  
set(gca,'TickLabelInterpreter','LaTex')
xlabel('Transfer in \$k','Interpreter','LaTex','Fontsize',12)
ylabel('Marginal rates: top-10 minus all','Interpreter','LaTex','Fontsize',12)
leg = legend([h1 h3 h7],{'Benchmark','No Pareto','Richer Poor'});
set(leg,'Interpreter','LaTex','Location','SouthWest','Fontsize',12)
xlim([10 23])
ylim([-0.25 0.18])
legend boxoff
run graph_extended.m
saveas(gcf,'TamtrLine_Inc_bw.pdf')
saveas(gcf,'TamtrLine_Inc_bw','epsc')

